#include <iostream>
#include <conio.h>
using namespace std;
int matran[32][32];
void khoitaomatran()
{ int x=1;
 int i =0;
 while(i<32){
 	int j=0;
 	while(j<32){
 		matran[i][j]=x;
		 x=x+1;
 		j++;
 	}
 	i++;
 }	
}
void xepmatran()
{ 
	int i=0;
	while(i<32)
	{
		int j=0;
		while(j<32){
		bool flag = false;
		if(j<8 && i<8 )
			flag = true;
		if(j>=24 && i<8 )
			flag = true;
		if(i>=24 && j>=24)	
			flag = true;
		if(i>=24 && j<8)	
			flag = true;
		if(8<=i && i <24 && 8<=j && j<24)
			flag = true;			
		if(flag)
			matran[i][j]=32*32 +1 - matran[i][j];
		j++;
		}
		i++;
	}
}
void hienthi(){
	
	int i =0;
 	while(i<32){
	 	int j=0;
	 	while(j<32){
	 		cout<<matran[i][j]<<"\t";		
	 		j++;
	 	}
	 	i++;
	 	cout<<endl;
 	}
 
}
int check(int sum){
	
        int i = 0;
        while(i<32)
        {   
        		int sumhang = 0;
				int sumcot =0;
				int sumduongcheo =0;
				int sumduongcheo1=0;
                int j = 0;
                while(j<32)
                {
                        sumhang += matran[j][i];
                        sumcot += matran[i][j];
                        sumduongcheo += matran[j][j];
                        sumduongcheo1 += matran[j][31-j];
                        j = j+1;
                }
                if(sumhang!=sum || sumcot!=sum || sumduongcheo!= sum || sumduongcheo1!=sum)
               return 0;
                i = i+1;
        }
        return 1;
}
int main(){
	khoitaomatran();
	xepmatran();
	
    int sum = 16400;
    if(check(sum))
    {
            cout<<"Magic Square with 32 x32 size  : \n\n\n";
            hienthi();
            cout<<"\ntotal is : 16400";
            cout<<"\n";
    }
}























































































